• Tempo of Gene Expression
  • Build GCN (stepwise)
  • Build GCN (oneshot)
  • Rhy genes across tissues
  • Contact

On this page

  • ONE-SHOT (make_modules)
    • Make and plot modules
    • Modify network plot
  • Annotate the network
    • Identify rhythmic modules

Compare time-course gene expression data across tissues


Last updated on 2025-09-05.


Show code
library(dplyr)
library(dbplyr)
library(ggplot2)
for (i in list.files(here::here("R"), full.names = TRUE)) {
  source(i)
}

# SAMPLE NAME
## specify sample name
sample.names <- c(
  # dmel
  # "dmel-head",
  # "dmel-body",
  # "dmel-heart"
  # # mmus
  "mmus-brain_stem", 
  "mmus-cerebellum", 
  "mmus-hypothalamus", 
  "mmus-heart"
  # # panu
  # "panu-brain_stem",
  # "panu-cerebellum",
  # "panu-hypothalamus",
  # "panu-heart",
  # "panu-scn"
)
# sample.cycles <- c("LD", "DD")

## SPECIFY THE DATASET TO BUILD GCN WITH
which.sample <- "dmel-heart"

writeLines(
  glue::glue("Sample: {which.sample}")
)
Sample: dmel-heart
Structure of input data:

ONE-SHOT (make_modules)

Make and plot modules

Show code
mods <- purrr::map(
  sample.names,
  ~ timecourseRnaseq::make_modules(
      data = tidydata.db[[.x]],
      log2 = TRUE,
      id_column = "gene_name",
      min_expression = NULL,  # automatically estimated
      min_timepoints = NULL,  # automatically estimated
      method = "wgcna",
      qc = TRUE,
      sim_method = "kendall",
      soft_power = 15,      # automatically estimated
      min_module_size = 50,
      max_modules = 16,
      merge_cutoff_similarity = 0.9,
      plot_network_min_edge = 0.5,
      plot_network = FALSE,
      tidy_modules = TRUE
    )
) |>
  setNames(
    sample.names
  )
---------------------------------------------------
1. Log2-transform and subset 
---------------------------------------------------
Applying log2-transformation...Done.
Estimated min_expression = 8 
Estimated min_timepoints = 6 
Subsetting data...Done.
[ NOTE ]: After subsetting, 8893 of 17406 rows remain.

 Flagging genes and samples with too many missing values...
  ..step 1
All okay!Visualizing the log-transformed data
---------------------------------------------------
2. Calculate similarity of expression 
---------------------------------------------------
Running gene-gene similarity...Done.


---------------------------------------------------
3. Create adjacency matrix 
---------------------------------------------------
Performing network topology analysis to pick
  soft-thresholding power...
   Power SFT.R.sq   slope truncated.R.sq mean.k. median.k. max.k.
1      1   0.7240  1.9500          0.654    4510    4900.0   6020
2      2   0.5090  0.5730          0.389    2970    3230.0   4790
3      3   0.0298  0.0544          0.363    2170    2280.0   4040
4      4   0.2950 -0.1720          0.710    1690    1680.0   3510
5      5   0.6060 -0.3070          0.785    1360    1280.0   3110
6      6   0.7420 -0.3970          0.817    1130     995.0   2800
7      7   0.8110 -0.4740          0.818     951     790.0   2540
8      8   0.8540 -0.5280          0.841     815     634.0   2330
9      9   0.8860 -0.5790          0.866     708     516.0   2140
10    10   0.8960 -0.6210          0.868     621     424.0   1980
11    12   0.9040 -0.6890          0.877     489     294.0   1730
12    15   0.9040 -0.7770          0.886     359     182.0   1440
13    18   0.8990 -0.8420          0.895     275     118.0   1220
14    21   0.8930 -0.8910          0.899     216      80.2   1050

Plotting resutls from the network topology analysis...

Done.
[ NOTE, FIGURE ]: Red horizontal line indicates a signed R^2 of 0.9

Setting soft-thresholding power to: 15.
Power-transforming the gene-gene similarity matrix...Done.

---------------------------------------------------
4. Convert into topological overlap matrix (dissTOM) 
---------------------------------------------------
Creating dissTOM...Done.
Performing hierarchical clustering on dissTOM...Done.

---------------------------------------------------
5. Identify modules (clusters) 
---------------------------------------------------
Merging modules that have a correlation ≥ 0.9 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
  antiquewhite4         bisque4           black            blue           blue2 
            395              90             279            1931              56 
         brown2          brown4          coral1          coral2            cyan 
             56              95             747             165             159 
    darkmagenta darkolivegreen4   darkslateblue   darkturquoise      darkviolet 
            218             166             151             134              56 
     firebrick4     greenyellow          grey60           ivory      lightcyan1 
             61             169             145              98              99 
     lightgreen     lightyellow         magenta          maroon    mediumorchid 
            144             143             346              82             314 
  mediumpurple2   mediumpurple3    midnightblue    navajowhite2      orangered3 
             65             190             154              83              68 
     orangered4   paleturquoise            pink           plum3          purple 
            102             226             180              53             170 
            red     saddlebrown         skyblue        skyblue1       steelblue 
            188             121             121              70             119 
       thistle3       turquoise          violet          yellow         yellow4 
             52             257             113             190              72 
Merging modules that have a correlation ≥ 0.85 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
antiquewhite4       bisque4         black          blue         blue2 
          395           255          1104          3283           128 
       brown2        coral1   darkmagenta darkslateblue    firebrick4 
           56          1551           218           151            61 
  greenyellow        grey60         ivory    lightcyan1    lightgreen 
          288           328            98            99           144 
  lightyellow        maroon mediumpurple2  midnightblue  navajowhite2 
          143            82            65           154            83 
   orangered4         plum3      thistle3 
          102            53            52 
Merging modules that have a correlation ≥ 0.8 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.
Module (cluster) size:
mergedColors
antiquewhite4       bisque4         black          blue         blue2 
          796           255          2809          3025           456 
       brown2   darkmagenta darkslateblue         ivory    lightcyan1 
           56           608           151            98           164 
   lightgreen   lightyellow  navajowhite2         plum3      thistle3 
          144           143            83            53            52 

Cutoff used: 0.8 
Number of modules identified: 15 

Calculating module-module similarity based
  on module-eigengene-expression...Done.
Tidying module names...Done.
Plotting adjacency matrix for module-module similarity...

---------------------------------------------------
6. Tidy modules (clusters) 
---------------------------------------------------
---------------------------------------------------
1. Log2-transform and subset 
---------------------------------------------------
Applying log2-transformation...Done.
Estimated min_expression = 8 
Estimated min_timepoints = 6 
Subsetting data...Done.
[ NOTE ]: After subsetting, 8595 of 17130 rows remain.

 Flagging genes and samples with too many missing values...
  ..step 1
All okay!Visualizing the log-transformed data
---------------------------------------------------
2. Calculate similarity of expression 
---------------------------------------------------
Running gene-gene similarity...Done.


---------------------------------------------------
3. Create adjacency matrix 
---------------------------------------------------
Performing network topology analysis to pick
  soft-thresholding power...
   Power SFT.R.sq   slope truncated.R.sq mean.k. median.k. max.k.
1      1  0.74300  2.1000          0.915  3700.0    3770.0   5020
2      2  0.36800  0.5340          0.756  2170.0    2140.0   3640
3      3  0.00923 -0.0497          0.550  1450.0    1370.0   2860
4      4  0.38300 -0.3470          0.698  1040.0     925.0   2350
5      5  0.68800 -0.5610          0.837   790.0     660.0   1990
6      6  0.79300 -0.7020          0.880   619.0     487.0   1720
7      7  0.84200 -0.8060          0.909   498.0     369.0   1510
8      8  0.86200 -0.8900          0.916   409.0     287.0   1340
9      9  0.87700 -0.9540          0.924   342.0     228.0   1200
10    10  0.89000 -1.0000          0.936   290.0     184.0   1080
11    12  0.91200 -1.0800          0.951   215.0     125.0    898
12    15  0.91500 -1.1700          0.955   146.0      74.8    705
13    18  0.91600 -1.2300          0.956   105.0      48.4    571
14    21  0.92500 -1.2700          0.966    78.6      33.1    474

Plotting resutls from the network topology analysis...

Done.
[ NOTE, FIGURE ]: Red horizontal line indicates a signed R^2 of 0.9

Setting soft-thresholding power to: 15.
Power-transforming the gene-gene similarity matrix...Done.

---------------------------------------------------
4. Convert into topological overlap matrix (dissTOM) 
---------------------------------------------------
Creating dissTOM...Done.
Performing hierarchical clustering on dissTOM...Done.

---------------------------------------------------
5. Identify modules (clusters) 
---------------------------------------------------
Merging modules that have a correlation ≥ 0.9 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
        bisque4           black            blue           brown          brown4 
             87             737             403             471              88 
           cyan       darkgreen        darkgrey     darkmagenta  darkolivegreen 
            174             994             132             110             110 
     darkorange         darkred   darkseagreen4   darkslateblue   darkturquoise 
            128             136              50             236             134 
    floralwhite           green     greenyellow       honeydew1           ivory 
            192             302             177              53              92 
 lavenderblush3       lightcyan      lightcyan1      lightpink4 lightsteelblue1 
             57             157              93              57              93 
    lightyellow          maroon   mediumpurple3    midnightblue    navajowhite2 
            144              67              93             161              69 
         orange      orangered4   paleturquoise  palevioletred3            pink 
            129              93             115              70             445 
          plum1           plum2          purple             red       royalblue 
             94              84             334             380             140 
    saddlebrown          salmon         salmon4         skyblue       steelblue 
            116             175              71             116             116 
       thistle2          violet           white 
             81             112             127 
Merging modules that have a correlation ≥ 0.85 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
          black          brown4            cyan     darkmagenta  darkolivegreen 
           2839              88             846             110             203 
     darkorange         darkred   darkseagreen4   darkslateblue   darkturquoise 
            128             136              50             236             134 
          green     greenyellow       honeydew1  lavenderblush3       lightcyan 
            837             177              53              57             157 
     lightcyan1      lightpink4 lightsteelblue1     lightyellow          maroon 
             93             236              93             144              67 
   midnightblue    navajowhite2      orangered4  palevioletred3           plum2 
            161              69              93             186              84 
            red       royalblue     saddlebrown          salmon         salmon4 
            380             140             116             175              71 
      steelblue        thistle2          violet           white 
            116              81             112             127 
Merging modules that have a correlation ≥ 0.8 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
         brown4       darkgreen     darkmagenta  darkolivegreen      darkorange 
             88            2839             110             203            1435 
        darkred   darkseagreen4   darkturquoise           green     greenyellow 
            136              50             489             837             413 
      honeydew1  lavenderblush3       lightcyan      lightcyan1      lightpink4 
             53              57             157              93             422 
lightsteelblue1          maroon    midnightblue    navajowhite2      orangered4 
             93              67             161             256             233 
    saddlebrown          salmon          violet 
            116             175             112 
Merging modules that have a correlation ≥ 0.75 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.
Module (cluster) size:
mergedColors
         brown4  darkolivegreen      darkorange         darkred   darkseagreen4 
             88             620             396            3441              50 
  darkturquoise  lavenderblush3       lightcyan      lightcyan1 lightsteelblue1 
            489              57             390              93              93 
         maroon  palevioletred3     saddlebrown          salmon          violet 
             67             422            2102             175             112 

Cutoff used: 0.75 
Number of modules identified: 15 

Calculating module-module similarity based
  on module-eigengene-expression...Done.
Tidying module names...Done.
Plotting adjacency matrix for module-module similarity...

---------------------------------------------------
6. Tidy modules (clusters) 
---------------------------------------------------
---------------------------------------------------
1. Log2-transform and subset 
---------------------------------------------------
Applying log2-transformation...Done.
Estimated min_expression = 8 
Estimated min_timepoints = 6 
Subsetting data...Done.
[ NOTE ]: After subsetting, 8889 of 17453 rows remain.

 Flagging genes and samples with too many missing values...
  ..step 1
All okay!Visualizing the log-transformed data
---------------------------------------------------
2. Calculate similarity of expression 
---------------------------------------------------
Running gene-gene similarity...Done.


---------------------------------------------------
3. Create adjacency matrix 
---------------------------------------------------
Performing network topology analysis to pick
  soft-thresholding power...
   Power SFT.R.sq   slope truncated.R.sq mean.k. median.k. max.k.
1      1  0.65100  2.5300          0.937  3640.0    3660.0   4910
2      2  0.28300  0.6280          0.872  2060.0    2010.0   3420
3      3  0.00341 -0.0432          0.800  1340.0    1250.0   2620
4      4  0.27700 -0.3990          0.824   940.0     839.0   2120
5      5  0.50400 -0.6390          0.833   698.0     593.0   1760
6      6  0.63600 -0.7980          0.865   538.0     434.0   1500
7      7  0.70000 -0.9220          0.877   426.0     328.0   1300
8      8  0.74100 -1.0200          0.886   346.0     254.0   1140
9      9  0.76300 -1.1000          0.888   285.0     201.0   1010
10    10  0.78700 -1.1600          0.901   239.0     163.0    909
11    12  0.81700 -1.2500          0.918   174.0     110.0    743
12    15  0.84200 -1.3600          0.931   116.0      66.7    572
13    18  0.82400 -1.4700          0.914    81.5      43.4    456
14    21  0.84100 -1.5100          0.927    59.9      29.7    372

Plotting resutls from the network topology analysis...

Done.
[ NOTE, FIGURE ]: Red horizontal line indicates a signed R^2 of 0.9

Setting soft-thresholding power to: 15.
Power-transforming the gene-gene similarity matrix...Done.

---------------------------------------------------
4. Convert into topological overlap matrix (dissTOM) 
---------------------------------------------------
Creating dissTOM...Done.
Performing hierarchical clustering on dissTOM...Done.

---------------------------------------------------
5. Identify modules (clusters) 
---------------------------------------------------
Merging modules that have a correlation ≥ 0.9 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
  antiquewhite4         bisque4           black            blue           blue2 
             74              94             844             299              59 
          brown          brown2          brown4          coral1          coral2 
            210              60              95              76              73 
      darkgreen        darkgrey  darkolivegreen darkolivegreen4      darkorange 
            126             122             110              60             550 
    darkorange2         darkred   darkslateblue   darkturquoise      darkviolet 
             96             126             411             241              57 
    floralwhite          grey60       honeydew1      indianred4           ivory 
             96             139              79              62              97 
 lavenderblush3      lightcoral       lightcyan      lightcyan1      lightgreen 
             79              63             139              98             652 
     lightpink4  lightsteelblue lightsteelblue1         magenta          maroon 
             80              65              99             156              82 
   mediumorchid   mediumpurple2   mediumpurple3    midnightblue    navajowhite2 
             73              65              99             145              83 
         orange      orangered3      orangered4   paleturquoise  palevioletred2 
            121              65             101             112              52 
 palevioletred3            plum           plum1           plum2          purple 
             84              69             101             160             156 
            red       royalblue         salmon2         salmon4         skyblue 
            515             128              52              85             119 
       skyblue1         thistle        thistle1        thistle2        thistle3 
             71              55              86              89              55 
         yellow         yellow4     yellowgreen 
            204              71             104 
Merging modules that have a correlation ≥ 0.85 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
  antiquewhite4         bisque4            blue           blue2           brown 
             74             329             299              59             210 
         brown2          brown4          coral1          coral2       darkgreen 
             60              95              76              73             191 
       darkgrey  darkolivegreen darkolivegreen4     darkorange2   darkturquoise 
            330             486              60             748             241 
     darkviolet          grey60       honeydew1      indianred4           ivory 
           1139             139             239              62              97 
     lightcoral       lightcyan      lightcyan1      lightpink4  lightsteelblue 
             63             139              98              80              65 
lightsteelblue1    mediumorchid   mediumpurple3    midnightblue    navajowhite2 
             99             159              99             145              83 
         orange      orangered3      orangered4  palevioletred2  palevioletred3 
            121              65             101              52              84 
          plum1           plum3       royalblue         salmon2         salmon4 
            101            1295             128              52              85 
        skyblue        skyblue1         thistle        thistle2        thistle3 
            119              71              55              89              55 
         yellow         yellow4     yellowgreen 
            204              71             104 
Merging modules that have a correlation ≥ 0.8 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
  antiquewhite4            blue           blue2           brown          brown2 
             74             976              59             210              60 
         brown4          coral1          coral2        darkgrey darkolivegreen4 
            191            1817              73             982              60 
  darkturquoise          grey60           ivory      lightcoral      lightcyan1 
            625             139              97             202              98 
     lightpink4  lightsteelblue lightsteelblue1   mediumpurple3    midnightblue 
             80             238             262              99             264 
   navajowhite2      orangered4  palevioletred2  palevioletred3         salmon4 
             83            1589              52              84              85 
       skyblue1         thistle        thistle2     yellowgreen 
             71              55             160             104 
Merging modules that have a correlation ≥ 0.75 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
 antiquewhite4          blue2          brown         brown2           cyan 
            74             59            283             60           1817 
     darkgreen       darkgrey  darkturquoise          ivory     lightcoral 
           976           3136            625            359            202 
    lightcyan1     lightpink4  mediumpurple3   midnightblue   navajowhite2 
           336             80             99            264             83 
palevioletred2 palevioletred3        salmon4        thistle       thistle2 
            52             84             85             55            160 
Merging modules that have a correlation ≥ 0.7 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.
Module (cluster) size:
mergedColors
 antiquewhite4          blue2          brown         brown2           cyan 
            74             59            283             60           1817 
     darkgreen          ivory     lightcoral     lightcyan1     lightpink4 
          1031            359            202            336            240 
 mediumpurple3   midnightblue   navajowhite2     orangered4 palevioletred2 
           724            264            168           3136             52 
palevioletred3 
            84 

Cutoff used: 0.7 
Number of modules identified: 16 

Calculating module-module similarity based
  on module-eigengene-expression...Done.
Tidying module names...Done.
Plotting adjacency matrix for module-module similarity...

---------------------------------------------------
6. Tidy modules (clusters) 
---------------------------------------------------
---------------------------------------------------
1. Log2-transform and subset 
---------------------------------------------------
Applying log2-transformation...Done.
Estimated min_expression = 7 
Estimated min_timepoints = 6 
Subsetting data...Done.
[ NOTE ]: After subsetting, 9626 of 16619 rows remain.

 Flagging genes and samples with too many missing values...
  ..step 1
All okay!Visualizing the log-transformed data
---------------------------------------------------
2. Calculate similarity of expression 
---------------------------------------------------
Running gene-gene similarity...Done.


---------------------------------------------------
3. Create adjacency matrix 
---------------------------------------------------
Performing network topology analysis to pick
  soft-thresholding power...
   Power SFT.R.sq  slope truncated.R.sq mean.k. median.k. max.k.
1      1  0.63000  4.740          0.958  3510.0    3590.0   4390
2      2  0.36500  1.640          0.914  1810.0    1850.0   2700
3      3  0.07800  0.483          0.865  1100.0    1100.0   1880
4      4  0.00597 -0.112          0.839   726.0     719.0   1400
5      5  0.10400 -0.455          0.846   512.0     495.0   1090
6      6  0.23800 -0.709          0.860   377.0     356.0    879
7      7  0.35800 -0.901          0.883   287.0     265.0    724
8      8  0.45000 -1.040          0.900   225.0     202.0    607
9      9  0.52800 -1.140          0.924   180.0     158.0    517
10    10  0.58600 -1.220          0.940   146.0     126.0    446
11    12  0.66100 -1.400          0.953   101.0      83.0    344
12    15  0.73200 -1.590          0.971    63.1      48.9    250
13    18  0.77000 -1.760          0.979    42.3      31.0    192
14    21  0.78800 -1.910          0.979    29.9      20.8    154

Plotting resutls from the network topology analysis...

Done.
[ NOTE, FIGURE ]: Red horizontal line indicates a signed R^2 of 0.9

Setting soft-thresholding power to: 15.
Power-transforming the gene-gene similarity matrix...Done.

---------------------------------------------------
4. Convert into topological overlap matrix (dissTOM) 
---------------------------------------------------
Creating dissTOM...Done.
Performing hierarchical clustering on dissTOM...Done.

---------------------------------------------------
5. Identify modules (clusters) 
---------------------------------------------------
Merging modules that have a correlation ≥ 0.9 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
  antiquewhite4         bisque4           black            blue           blue2 
             79              99             183             239              62 
          brown          brown2          brown4          coral1          coral2 
            231              62             100              79              78 
           cyan       darkgreen        darkgrey     darkmagenta  darkolivegreen 
            258             128             124             112             201 
darkolivegreen4      darkorange     darkorange2         darkred   darkseagreen3 
             65             124             100             132              51 
  darkseagreen4   darkslateblue   darkturquoise      darkviolet      firebrick4 
             79              97             126              61              67 
    floralwhite           green     greenyellow          grey60        honeydew 
            103             186             159             253              52 
      honeydew1      indianred4           ivory  lavenderblush2  lavenderblush3 
            190              68             105              52              80 
     lightcoral       lightcyan      lightcyan1      lightgreen      lightpink3 
             69             150             106             143              54 
     lightpink4  lightsteelblue     lightyellow         magenta        magenta4 
             83              70             139             179              54 
         maroon    mediumorchid   mediumpurple2   mediumpurple3    midnightblue 
             83              76              71             107             151 
   navajowhite1          orange      orangered3      orangered4   paleturquoise 
             58             214              71             107             119 
 palevioletred2  palevioletred3            pink            plum           plum2 
             59              89             182              71              96 
          plum3          purple             red       royalblue     saddlebrown 
             61             162             185             135             120 
         salmon         salmon2         salmon4         skyblue        skyblue1 
            153              60              89             122              73 
       skyblue2        skyblue3       steelblue             tan         thistle 
             76             108             119             154              61 
       thistle2        thistle3       turquoise          violet           white 
             93              61             369             116             123 
         yellow         yellow4     yellowgreen 
            216              75             109 
Merging modules that have a correlation ≥ 0.85 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
  antiquewhite4         bisque4           black            blue           blue2 
             79             223             397             497              62 
         brown2          brown4          coral1          coral2       darkgreen 
             62             100              79             249             128 
    darkmagenta  darkolivegreen darkolivegreen4      darkorange         darkred 
            220             201              65             124             132 
  darkseagreen3   darkseagreen4   darkslateblue   darkturquoise      darkviolet 
             51              79              97             126              61 
     firebrick4     floralwhite           green     greenyellow          grey60 
             67             103             186             298             376 
       honeydew       honeydew1      indianred4           ivory  lavenderblush2 
             52             343             143             247              52 
 lavenderblush3       lightcyan      lightcyan1      lightgreen      lightpink3 
             80             431             106             143              54 
     lightpink4  lightsteelblue         magenta        magenta4          maroon 
             83              70             779              54              83 
   mediumorchid   mediumpurple2   mediumpurple3    midnightblue    navajowhite1 
             76              71             107             212              58 
     orangered3      orangered4   paleturquoise  palevioletred2  palevioletred3 
             71             107             119              59              89 
           pink          purple       royalblue     saddlebrown         salmon2 
            182             162             135             120              60 
        salmon4         skyblue        skyblue2       steelblue             tan 
             89             122              76             119             154 
        thistle        thistle2        thistle3          violet          yellow 
             61              93              61             116             216 
    yellowgreen 
            109 
Merging modules that have a correlation ≥ 0.8 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
  antiquewhite4         bisque4           black            blue           blue2 
            259            1109             397             558              62 
         brown2          brown4          coral1  darkolivegreen darkolivegreen4 
             62             100             435             201              65 
     darkorange     darkorange2         darkred   darkseagreen3   darkseagreen4 
            124             249             132              51             172 
  darkslateblue   darkturquoise      firebrick4     floralwhite           green 
             97             126              67             103             186 
    greenyellow        honeydew      indianred4  lavenderblush3      lightcyan1 
            476              52             143            1086             179 
     lightpink3      lightpink4  lightsteelblue        magenta4          maroon 
             54             154              70              54              83 
   mediumorchid    navajowhite1      orangered3      orangered4   paleturquoise 
             76              58              71             107             119 
 palevioletred3          purple       royalblue     saddlebrown          salmon 
             89             162             351             120             343 
        salmon2         salmon4         skyblue        skyblue2             tan 
             60              89             122              76             154 
        thistle        thistle3          violet           white     yellowgreen 
             61              61             116             376             109 
Merging modules that have a correlation ≥ 0.75 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
          blue2          brown2          brown4       darkgreen  darkolivegreen 
            432              62             100             259            1322 
darkolivegreen4      darkorange     darkorange2         darkred   darkseagreen3 
             65             124             249             132             448 
  darkseagreen4   darkslateblue   darkturquoise      firebrick4     floralwhite 
            172             167             126              67             103 
       honeydew      indianred4           ivory  lavenderblush3      lightpink3 
             52             143             353            1086              54 
     lightpink4         magenta        magenta4          maroon    mediumorchid 
           1224            1109              54              83              76 
   navajowhite1      orangered3   paleturquoise  palevioletred3          purple 
             58              71             119             165             162 
    saddlebrown         salmon2         salmon4         skyblue       steelblue 
            181              60              89             122             476 
       thistle3 
             61 
Merging modules that have a correlation ≥ 0.7 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
          blue2          brown2          brown4       darkgreen darkolivegreen4 
            432             592             100             259             191 
     darkorange     darkorange2         darkred   darkseagreen3   darkseagreen4 
            124             416             132             710             239 
     darkviolet        honeydew      indianred4           ivory      lightpink3 
           1121            1161            1229             353              54 
         maroon    mediumorchid    navajowhite1      orangered3   paleturquoise 
             83              76             239              71             119 
 palevioletred3          purple          salmon         salmon2         salmon4 
            165             162            1327             182              89 
Merging modules that have a correlation ≥ 0.65 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.

Module (cluster) size:
mergedColors
         brown2          brown4       darkgreen darkolivegreen4      darkorange 
            592             152             259             191             124 
    darkorange2         darkred   darkseagreen3      firebrick4      indianred4 
           1525             208            1950             239            1229 
          ivory      lightpink3      lightpink4          maroon    navajowhite1 
            353              54            1327             515             239 
     orangered3  palevioletred3          purple         salmon2         salmon4 
             71             165             162             182              89 
Merging modules that have a correlation ≥ 0.6 ...Done.
[ NOTE, FIGURE ] Plotting identified clusters before and after merging.
Module (cluster) size:
mergedColors
         brown2          brown4       darkgreen darkolivegreen4      darkorange 
            592             152             259             430             124 
    darkorange2         darkred   darkseagreen3      lightpink3          maroon 
           1525             208            1834              54             515 
 palevioletred3          salmon         salmon2         salmon4 
           1667            1995             182              89 

Cutoff used: 0.6 
Number of modules identified: 14 

Calculating module-module similarity based
  on module-eigengene-expression...Done.
Tidying module names...Done.
Plotting adjacency matrix for module-module similarity...

---------------------------------------------------
6. Tidy modules (clusters) 
---------------------------------------------------
Show code
# mods <- timecourseRnaseq::make_modules(
#   data = tidydata.db[[which.sample]],
#   log2 = TRUE,
#   id_column = "gene_name",
#   min_expression = NULL,  # automatically estimated
#   min_timepoints = NULL,  # automatically estimated
#   method = "wgcna",
#   qc = TRUE,
#   sim_method = "kendall",
#   soft_power = 15,      # automatically estimated
#   min_module_size = 50,
#   max_modules = 16,
#   merge_cutoff_similarity = 0.9,
#   plot_network_min_edge = 0.5,
#   plot_network = TRUE,
#   tidy_modules = TRUE
#   )

Modify network plot

Internal function; use ::: to call

Show code
trash <- purrr::map(
  sample.names,
  ~ timecourseRnaseq:::plot_adj_as_network(
      matrix = mods[[.x]][["adj_matrix_ME"]][["ME"]],
      # layout = igraph::layout.sugiyama,
      layout = igraph::layout_in_circle, # changed 
      min_edge = 0.6,
      node_label_size = 1.2,
      node_size = 20,
      edge_size = 3,
      node_frame_col = "grey20",
      node_fill_col = "grey80",
      vertex.frame.width = 3
    )
)
Visualizing a simplified representation of the circadian GCN

Visualizing a simplified representation of the circadian GCN

Visualizing a simplified representation of the circadian GCN

Visualizing a simplified representation of the circadian GCN

Annotate the network

Obtain a list of genes in each module

Show code
module_genes <- purrr::map(
  sample.names,
  ~ mods[[.x]][["module_genes"]]
) |> 
  setNames(sample.names)

Identify rhythmic modules

Show code
db_rhy <- purrr::map(
  sample.names,
  ~ load_rhy_genes(
      sample = .x
    )
) |> 
  setNames(sample.names)

###-###-###-###-###-###-###-###-
# Set your p-value of choice
# col_pval = "BH.Q"
col_pval = "default.pvalue"
# col_pval = "raw.pvalue"
###-###-###-###-###-###-###-###-
l_module_genes <- purrr::map(
  sample.names,
  ~ module_genes[[.x]] |> 
    arrange(module_identity) |> 
    group_split(module_identity) |> 
    purrr::map(
      ~ .x |> pull(gene_name)
    ) |> 
    setNames(unique(module_genes[[.x]]$module_identity))
) |> 
  setNames(sample.names)

l_rhy_genes <- purrr::map(
  sample.names,
  ~ db_rhy[[.x]] |> 
    purrr::map(
      ~ .x |> 
        filter(
          if_all(
            all_of(col_pval),
            ~ .x < 0.05
          )
        ) |> 
        filter(
          ID %in% unlist(l_module_genes)
        ) |> 
        pull(1) |> 
        unique()
    ) |> 
    purrr::compact()
) |> 
  setNames(sample.names)

Modules vs. Rhythmic genes

Show code
trash <- purrr::map(
  sample.names,
  function(x) {
    writeLines("
    #####################################################
    How many genes are in each of my geneset of interest?
    #####################################################")
    
    ## MAKE YOUR LIST OF GENES OF INTEREST ##
    
    # LIST ONE - WGCNA modules
    list1 <- l_module_genes[[x]]
    sapply(list1, length) |> print()
    
    ## LIST TWO - rhythmic genes
    list2 <- l_rhy_genes[[x]]
    sapply(list2, length) |> print()
    
    ## CHECK FOR OVERLAP
    # define size of genome
    size = length(unique(c(unlist(list1), unlist(list2))))
    # make a GOM object
    gom.1v2 <- GeneOverlap::newGOM(
      list2, 
      list1,
      genome.size = size
    )
    GeneOverlap::drawHeatmap(
      gom.1v2,
      adj.p = TRUE,
      cutoff=0.05,
      what="odds.ratio",
      # what="Jaccard",
      log.scale = T,
      note.col = "black",
      grid.col = "Oranges"
    )
  }
)

    #####################################################
    How many genes are in each of my geneset of interest?
    #####################################################
  C1   C2   C3   C4   C5   C6   C7   C8   C9  C10  C11  C12  C13  C14  C15 
 456  151   98  164  144  796   56  143 2809  608   83   53  255 3025   52 
      ARS    empJTK GeneCycle       JTK    meta2d      RAIN 
     1383       482       538       254      1059       870 


    #####################################################
    How many genes are in each of my geneset of interest?
    #####################################################
  C1   C2   C3   C4   C5   C6   C7   C8   C9  C10  C11  C12  C13  C14  C15 
  88 3441   93  175   57  489  422  390  396 2102  620   67  112   50   93 
      ARS    empJTK GeneCycle       JTK    meta2d      RAIN 
     3311       872       844       328      2434       781 


    #####################################################
    How many genes are in each of my geneset of interest?
    #####################################################
  C1   C2   C3   C4   C5   C6   C7   C8   C9  C10  C11  C12  C13  C14  C15  C16 
1817  336 3136  359  202  168   59  283  724   74  240   60   84   52 1031  264 
      ARS    empJTK GeneCycle       JTK    meta2d      RAIN 
     2535       725       605       299      1655       809 


    #####################################################
    How many genes are in each of my geneset of interest?
    #####################################################
  C1   C2   C3   C4   C5   C6   C7   C8   C9  C10  C11  C12  C13  C14 
 208 1995 1834  515  259  124 1667  592  182   89   54  152 1525  430 
      ARS    empJTK GeneCycle       JTK    meta2d      RAIN 
     3319      1281      1039       707      2934      1712